import {
	BaiduImageryProvider
} from "../Provider/BaiduImageryProvider.js"

class TileLayer {
	constructor(viewer) {
		this._viewer = viewer;
		this._scene = viewer.scene;
		this._map = new Map();
	}
	
	/**
	 * @description 判断url加上配置的代理
	 * @param {Object} config
	 */
	getProxyUrl(config) {
		if (!config.proxy || !config.url) return config;
		if (config.url instanceof Cesium.Resource) return config;
		var opts = {};
		for (var key in config) {
			opts[key] = config[key];
		}
		opts.url = new Cesium.Resource({
			url: opts.url,
			proxy: new Cesium.DefaultProxy(opts.proxy)
		});
		return opts;
	}
	
	/**
	 * @description 添加图层
	 * @param {Object} options
	 * @param {Function} complete
	 */
	add(options, complete) {
		let id = Cesium.defaultValue(options.id, Cesium.createGuid())
		if (!this._map.has(id)) {
			let layer = this.create(options);
			if (Cesium.defined(layer)) {
				if (Cesium.defined(options.index)) {
					this._map.set(id, this._viewer.imageryLayers.addImageryProvider(layer, options.index))
				} else {
					this._map.set(id, this._viewer.imageryLayers.addImageryProvider(layer))
				}
				if (complete) {
					complete({
						code: 200,
						message: '成功.',
						data: {
							id: id,
							layer: this._map.get(id)
						}
					});
				}
				return this._map.get(id);

			}
			if (complete) {
				complete({
					code: 500,
					message: '失败.'
				});
			}
		} else {
			if (complete) {
				complete({
					code: 200,
					message: '成功.',
					data: {
						id: id,
						layer: this._map.get(id)
					}
				});
			}
			return this._map.get(id);
		}
	}
	
	/**
	 * @description 图层ID
	 * @param {Object} id
	 */
	getById(id) {
		return this._map.get(id);
	}

	/**
	 * @description  移出图层
	 * @param {Object} id
	 */
	remove(id) {
		if (this._map.has(id)) {
			let layer = this._map.get(id);
			if (this._viewer.imageryLayers.remove(this._map.get(id), true)) {
				this._map.delete(id);
				return true;
			}
		}
		return false;
	}

	/**
	 * @description 上移
	 * @param {Object} id
	 */
	raise(id) {
		if (this._map.has(id)) {
			return this._viewer.imageryLayers.raise(this._map.get(id))
		}
		return false;
	}

	/**
	 * @description 至顶
	 * @param {Object} id
	 */
	raiseToTop(id) {
		if (this._map.has(id)) {
			return this._viewer.imageryLayers.raiseToTop(this._map.get(id))
		}
		return false;
	}

	/**
	 * @description 至底部
	 * @param {Object} id
	 */
	lowerToBottom(id) {
		if (this._map.has(id)) {
			return this._viewer.imageryLayers.lowerToBottom(this._map.get(id))
		}
		return false;
	}

	/**
	 * @description 下移
	 * @param {Object} id
	 */
	lower(id) {
		if (this._map.has(id)) {
			return this._viewer.imageryLayers.lower(this._map.get(id))
		}
		return false;
	}

	/**
	 * @description 包含
	 * @param {Object} id
	 */
	contains(id) {
		return this._map.has(id)
	}

	/**
	 * @description 清空
	 */
	removeAll() {
		if (this._viewer.imageryLayers.removeAll()) {
			this._map.clear();
			return true;
		}
		return false;
	}

	/**
	 * @description 
	 * @param {Object} options
	 */
	create(options) {
		if ('tdt' == options.type) {
			return this.createTDT(options);
		}
		if ('amap' == options.type) {
			return this.createAMap(options);
		}
		if ('baidu' == options.type) {
			return new BaiduImageryProvider(options);
		}
		if ('osm' == options.type) {
			var _url = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
			if (options.proxy) //存在代理时
				_url = (0, this.getProxyUrl)({
					url: _url.replace('{s}', 'a'),
					proxy: options.proxy
				}).url;
			return new Cesium.UrlTemplateImageryProvider({
				url: _url,
				subdomains: "abc",
				maximumLevel: 18
			});
		}
		if ('bing' == options.type) {
			var _url = 'https://dev.virtualearth.net';
			if (options.proxy) //存在代理时
				_url = (0, _util.getProxyUrl)({
					url: _url,
					proxy: options.proxy
				}).url;
			//无标记影像 Aerial,
			//有英文标记影像   AerialWithLabels,
			//矢量道路  Road 
			//OrdnanceSurvey,
			//CollinsBart
			var style = options.layer || Cesium.BingMapsStyle.Aerial;
			return new Cesium.BingMapsImageryProvider({
				url: _url,
				key: options.key || 'AtkX3zhnRe5fyGuLU30uZw8r3sxdBDnpQly7KfFTCB2rGlDgXBG3yr-qEiQEicEc',
				mapStyle: style
			});
		}
		if ('ion' == options.type) {
			return new Cesium.IonImageryProvider({
				assetId: options.assetId,
				accessToken: options.accessToken,
			});
		}
		if ('ion' == options.type) {
			return new Cesium.IonImageryProvider({
				assetId: options.assetId,
				accessToken: options.accessToken,
			});
		}
		if ('osm' == options.type) {
			return new Cesium.OpenStreetMapImageryProvider({
				url: Cesium.defaultValue(options.url, 'https://a.tile.openstreetmap.org/'),
				minimumLevel: Cesium.defaultValue(options.minimumLevel, 0),
				maximumLevel: Cesium.defaultValue(options.minimumLevel, undefined),
				ellipsoid: Cesium.defaultValue(options.ellipsoid, Cesium.Ellipsoid.WGS84),
				credit: Cesium.defaultValue(options.credit, "")
			})
		} else if ('tms' == options.type) {
			return new Cesium.TileMapServiceImageryProvider({
				url: Cesium.defaultValue(options.url, Cesium.buildModuleUrl(
					'Assets/Textures/NaturalEarthII')),
				fileExtension: Cesium.defaultValue(options.fileExtension, 'png'),
				credit: Cesium.defaultValue(options.credit, ""),
				rectangle: Cesium.defaultValue(options.rectangle, Cesium.Rectangle.MAX_VALUE),
				minimumLevel: Cesium.defaultValue(options.minimumLevel, 0),
				maximumLevel: Cesium.defaultValue(options.minimumLevel, undefined),
				tilingScheme: Cesium.defaultValue(options.tilingScheme, new Cesium.WebMercatorTilingScheme({
					numberOfLevelZeroTilesX: 1,
					numberOfLevelZeroTilesY: 1,
				})),
				tileWidth: Cesium.defaultValue(options.tileWidth, 256),
				tileHeight: Cesium.defaultValue(options.tileHeight, 256),
				ellipsoid: Cesium.defaultValue(options.ellipsoid, Cesium.Ellipsoid.WGS84),
				flipXY: Cesium.defaultValue(options.flipXY, false)
			})
		} else if ('arcgis' == options.type) {
			let arcGisMap = {
				url: Cesium.defaultValue(options.url,
					'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'),
			};
			if (Cesium.defined(options.token)) {
				arcGisMap.token = Cesium.defaultValue(options.token, "")
			}
			if (Cesium.defined(options.tileDiscardPolicy)) {
				arcGisMap.tileDiscardPolicy = Cesium.defaultValue(options.tileDiscardPolicy, "")
			}
			if (Cesium.defined(options.usePreCachedTilesIfAvailable)) {
				arcGisMap.usePreCachedTilesIfAvailable = Cesium.defaultValue(options.usePreCachedTilesIfAvailable,
					true)
			}
			if (Cesium.defined(options.layers)) {
				arcGisMap.layers = Cesium.defaultValue(options.layers, undefined)
			}
			if (Cesium.defined(options.enablePickFeatures)) {
				arcGisMap.enablePickFeatures = Cesium.defaultValue(options.enablePickFeatures, true)
			}
			if (Cesium.defined(options.rectangle)) {
				arcGisMap.rectangle = Cesium.defaultValue(options.rectangle, Cesium.Rectangle.MAX_VALUE)
			}
			if (Cesium.defined(options.tilingScheme)) {
				arcGisMap.tilingScheme = Cesium.defaultValue(options.tilingScheme, new Cesium
					.GeographicTilingScheme())
			}
			if (Cesium.defined(options.ellipsoid)) {
				arcGisMap.ellipsoid = Cesium.defaultValue(options.ellipsoid, Cesium.Ellipsoid.WGS84)
			}
			if (Cesium.defined(options.credit)) {
				arcGisMap.credit = Cesium.defaultValue(options.credit, "")
			}
			if (Cesium.defined(options.tileWidth)) {
				arcGisMap.tileWidth = Cesium.defaultValue(options.tileWidth, 256)
			}
			if (Cesium.defined(options.tileHeight)) {
				arcGisMap.tileHeight = Cesium.defaultValue(options.tileHeight, 256)
			}
			if (Cesium.defined(options.maximumLevel)) {
				arcGisMap.maximumLevel = Cesium.defaultValue(options.maximumLevel, undefined)
			}
			return new Cesium.ArcGisMapServerImageryProvider(arcGisMap)
		} else if ('bing' == options.type) {
			let bingMap = {
				url: Cesium.defaultValue(options.url, 'https://dev.virtualearth.net'),
			};
			if (Cesium.defined(options.token)) {
				bingMap.key = Cesium.defaultValue(options.token, "get-yours-at-https://www.bingmapsportal.com/")
			}
			if (Cesium.defined(options.mapStyle)) {
				bingMap.mapStyle = Cesium.defaultValue(options.mapStyle, Cesium.BingMapsStyle.AERIAL)
			}
			if (Cesium.defined(options.tileDiscardPolicy)) {
				bingMap.tileDiscardPolicy = Cesium.defaultValue(options.tileDiscardPolicy, undefined)
			}
			if (Cesium.defined(options.ellipsoid)) {
				bingMap.ellipsoid = Cesium.defaultValue(options.ellipsoid, Cesium.Ellipsoid.WGS84)
			}
			if (Cesium.defined(options.culture)) {
				bingMap.culture = Cesium.defaultValue(options.culture, "")
			}
			if (Cesium.defined(options.tileProtocol)) {
				bingMap.tileProtocol = Cesium.defaultValue(options.tileProtocol, "http")
			}
			return new Cesium.BingMapsImageryProvider(bingMap)
		} else if ('gee' == options.type) {
			let geeMap = {
				url: Cesium.defaultValue(options.url, 'https://earth.localdomain'),
			};
			if (Cesium.defined(options.channel)) {
				geeMap.channel = Cesium.defaultValue(options.channel, 1008)
			}
			if (Cesium.defined(options.path)) {
				geeMap.path = Cesium.defaultValue(options.path, "/default_map")
			}
			if (Cesium.defined(options.maximumLevel)) {
				geeMap.maximumLevel = Cesium.defaultValue(options.maximumLevel, undefined)
			}
			if (Cesium.defined(options.ellipsoid)) {
				geeMap.ellipsoid = Cesium.defaultValue(options.ellipsoid, Cesium.Ellipsoid.WGS84)
			}
			if (Cesium.defined(options.tileDiscardPolicy)) {
				geeMap.tileDiscardPolicy = Cesium.defaultValue(options.tileDiscardPolicy, undefined)
			}
			return new Cesium.GoogleEarthEnterpriseMapsProvider(geeMap)
		} else if ('single' == options.type || 'image' == options.type) {
			let singleMap = {
				url: Cesium.defaultValue(options.url, 'https://earth.localdomain'),
			};
			if (Cesium.defined(options.rectangle)) {
				singleMap.rectangle = Cesium.defaultValue(options.rectangle, Cesium.Rectangle.MAX_VALUE)
			}
			if (Cesium.defined(options.ellipsoid)) {
				singleMap.ellipsoid = Cesium.defaultValue(options.ellipsoid, Cesium.Ellipsoid.WGS84)
			}
			if (Cesium.defined(options.credit)) {
				singleMap.credit = Cesium.defaultValue(options.credit, "")
			}
			return new Cesium.SingleTileImageryProvider(singleMap)
		} else if ('wms' == options.type) {
			let wmsMap = {
				url: Cesium.defaultValue(options.url, ''),
			};
			if (Cesium.defined(options.layers)) {
				wmsMap.layers = Cesium.defaultValue(options.layers, "")
			}
			if (Cesium.defined(options.parameters)) {
				wmsMap.parameters = Cesium.defaultValue(options.parameters, Cesium.WebMapServiceImageryProvider
					.DefaultParameters)
			}
			if (Cesium.defined(options.getFeatureInfoParameters)) {
				wmsMap.getFeatureInfoParameters = Cesium.defaultValue(options.getFeatureInfoParameters, Cesium
					.WebMapServiceImageryProvider.GetFeatureInfoDefaultParameters)
			}
			if (Cesium.defined(options.enablePickFeatures)) {
				wmsMap.enablePickFeatures = Cesium.defaultValue(options.enablePickFeatures, true)
			}
			if (Cesium.defined(options.getFeatureInfoFormats)) {
				wmsMap.getFeatureInfoFormats = Cesium.defaultValue(options.getFeatureInfoFormats, Cesium
					.WebMapServiceImageryProvider.DefaultGetFeatureInfoFormats)
			}
			if (Cesium.defined(options.rectangle)) {
				wmsMap.rectangle = Cesium.defaultValue(options.rectangle, Cesium.Rectangle.MAX_VALUE)
			}
			if (Cesium.defined(options.tilingScheme)) {
				wmsMap.tilingScheme = Cesium.defaultValue(options.tilingScheme, new Cesium.GeographicTilingScheme())
			}
			if (Cesium.defined(options.ellipsoid)) {
				wmsMap.ellipsoid = Cesium.defaultValue(options.ellipsoid, Cesium.Ellipsoid.WGS84)
			}
			if (Cesium.defined(options.tileWidth)) {
				wmsMap.tileWidth = Cesium.defaultValue(options.tileWidth, 256)
			}
			if (Cesium.defined(options.tileHeight)) {
				wmsMap.tileHeight = Cesium.defaultValue(options.tileHeight, 256)
			}
			if (Cesium.defined(options.minimumLevel)) {
				wmsMap.minimumLevel = Cesium.defaultValue(options.minimumLevel, 0)
			}
			if (Cesium.defined(options.maximumLevel)) {
				wmsMap.maximumLevel = Cesium.defaultValue(options.maximumLevel, undefined)
			}
			if (Cesium.defined(options.crs)) {
				wmsMap.crs = Cesium.defaultValue(options.crs, undefined)
			}
			if (Cesium.defined(options.srs)) {
				wmsMap.srs = Cesium.defaultValue(options.srs, undefined)
			}
			if (Cesium.defined(options.credit)) {
				wmsMap.credit = Cesium.defaultValue(options.credit, "")
			}
			if (Cesium.defined(options.subdomains)) {
				wmsMap.subdomains = Cesium.defaultValue(options.subdomains, 'abc')
			}
			if (Cesium.defined(options.clock)) {
				wmsMap.clock = Cesium.defaultValue(options.clock, undefined)
			}
			if (Cesium.defined(options.times)) {
				wmsMap.times = Cesium.defaultValue(options.times, undefined)
			}
			return new Cesium.WebMapServiceImageryProvider(wmsMap)
		} else if ('wmts' == options.type) {
			let wmtsMap = {
				url: Cesium.defaultValue(options.url, ''),
			};
			if (Cesium.defined(options.format)) {
				wmtsMap.format = Cesium.defaultValue(options.format, 'image/jpeg')
			}
			if (Cesium.defined(options.layer)) {
				wmtsMap.layer = Cesium.defaultValue(options.layer, "")
			}
			if (Cesium.defined(options.style)) {
				wmtsMap.style = Cesium.defaultValue(options.style, "")
			}
			if (Cesium.defined(options.tileMatrixSetID)) {
				wmtsMap.tileMatrixSetID = Cesium.defaultValue(options.tileMatrixSetID, "")
			}
			if (Cesium.defined(options.tileMatrixLabels)) {
				wmtsMap.tileMatrixLabels = Cesium.defaultValue(options.tileMatrixLabels, undefined)
			}
			if (Cesium.defined(options.clock)) {
				wmtsMap.clock = Cesium.defaultValue(options.clock, undefined)
			}
			if (Cesium.defined(options.times)) {
				wmtsMap.times = Cesium.defaultValue(options.times, undefined)
			}
			if (Cesium.defined(options.dimensions)) {
				wmtsMap.dimensions = Cesium.defaultValue(options.dimensions, undefined)
			}
			if (Cesium.defined(options.subdomains)) {
				wmtsMap.subdomains = Cesium.defaultValue(options.subdomains, 'abc')
			}
			if (Cesium.defined(options.rectangle)) {
				wmtsMap.rectangle = Cesium.defaultValue(options.rectangle, Cesium.Rectangle.MAX_VALUE)
			}
			if (Cesium.defined(options.tilingScheme)) {
				wmtsMap.tilingScheme = Cesium.defaultValue(options.tilingScheme, undefined)
			}
			if (Cesium.defined(options.ellipsoid)) {
				wmsMap.ellipsoid = Cesium.defaultValue(options.ellipsoid, Cesium.Ellipsoid.WGS84)
			}
			if (Cesium.defined(options.tileWidth)) {
				wmtsMap.tileWidth = Cesium.defaultValue(options.tileWidth, 256)
			}
			if (Cesium.defined(options.tileHeight)) {
				wmtsMap.tileHeight = Cesium.defaultValue(options.tileHeight, 256)
			}
			if (Cesium.defined(options.minimumLevel)) {
				wmtsMap.minimumLevel = Cesium.defaultValue(options.minimumLevel, 0)
			}
			if (Cesium.defined(options.maximumLevel)) {
				wmtsMap.maximumLevel = Cesium.defaultValue(options.maximumLevel, undefined)
			}
			if (Cesium.defined(options.credit)) {
				wmtsMap.credit = Cesium.defaultValue(options.credit, "")
			}
			return new Cesium.WebMapTileServiceImageryProvider(wmtsMap)
		} else if ('xyz' == options.type) {
			let xyzMap = {
				url: Cesium.defaultValue(options.url, ''),
			};
			if (Cesium.defined(options.options)) {
				xyzMap.options = Cesium.defaultValue(options.options, undefined)
			}
			if (Cesium.defined(options.pickFeaturesUrl)) {
				xyzMap.pickFeaturesUrl = Cesium.defaultValue(options.pickFeaturesUrl, undefined)
			}
			if (Cesium.defined(options.urlSchemeZeroPadding)) {
				xyzMap.urlSchemeZeroPadding = Cesium.defaultValue(options.urlSchemeZeroPadding, undefined)
			}
			if (Cesium.defined(options.subdomains)) {
				xyzMap.subdomains = Cesium.defaultValue(options.subdomains, 'abc')
			}
			if (Cesium.defined(options.tileWidth)) {
				xyzMap.tileWidth = Cesium.defaultValue(options.tileWidth, 256)
			}
			if (Cesium.defined(options.tileHeight)) {
				xyzMap.tileHeight = Cesium.defaultValue(options.tileHeight, 256)
			}
			if (Cesium.defined(options.minimumLevel)) {
				xyzMap.minimumLevel = Cesium.defaultValue(options.minimumLevel, 0)
			}
			if (Cesium.defined(options.maximumLevel)) {
				xyzMap.maximumLevel = Cesium.defaultValue(options.maximumLevel, undefined)
			}
			if (Cesium.defined(options.rectangle)) {
				xyzMap.rectangle = Cesium.defaultValue(options.rectangle, Cesium.Rectangle.MAX_VALUE)
			}
			if (Cesium.defined(options.ellipsoid)) {
				xyzMap.ellipsoid = Cesium.defaultValue(options.ellipsoid, Cesium.Ellipsoid.WGS84)
			}
			if (Cesium.defined(options.credit)) {
				xyzMap.credit = Cesium.defaultValue(options.credit, "")
			}
			if (Cesium.defined(options.hasAlphaChannel)) {
				xyzMap.hasAlphaChannel = Cesium.defaultValue(options.hasAlphaChannel, true)
			}
			if (Cesium.defined(options.getFeatureInfoFormats)) {
				xyzMap.getFeatureInfoFormats = Cesium.defaultValue(options.getFeatureInfoFormats, undefined)
			}
			if (Cesium.defined(options.enablePickFeatures)) {
				xyzMap.enablePickFeatures = Cesium.defaultValue(options.enablePickFeatures, true)
			}
			if (Cesium.defined(options.customTags)) {
				xyzMap.customTags = Cesium.defaultValue(options.customTags, undefined)
			}
			return new Cesium.UrlTemplateImageryProvider(xyzMap)
		} else {
			return new Cesium.TileMapServiceImageryProvider({
				url: Cesium.buildModuleUrl('Assets/Textures/NaturalEarthII')
			});
		}
	}

	/**
	 * @description 创建天地图
	 * @param {Object} opts
	 */
	createTDT(opts) {
		var layer;
		var _layer;
		var maxLevel = 18;
		switch (opts.layer) {
			default:
			case "vec_d":
				_layer = "vec";
				break;
			case "vec_z":
				_layer = "cva";
				break;
			case "img_d":
				_layer = "img";
				break;
			case "img_z":
				_layer = "cia";
				break;
			case "ter_d":
				_layer = "ter";
				maxLevel = 14;
				break;
			case "ter_z":
				_layer = "cta";
				maxLevel = 14;
				break;
		}
		var _key = Cesium.defaultValue(opts.key, '87949882c75775b5069a0076357b7530');
		if (opts.crs == "4326" || opts.crs == "EPSG4326" || opts.crs == "EPSG:4326") {
			//wgs84   
			var matrixIds = new Array(maxLevel);
			for (var z = 0; z <= maxLevel; z++) {
				matrixIds[z] = (z + 1).toString();
			}
			var _url = 'https://t{s}.tianditu.gov.cn/' + _layer +
				'_c/wmts?service=WMTS&version=1.0.0&request=GetTile&tilematrix={TileMatrix}&layer=' + _layer +
				'&style={style}&tilerow={TileRow}&tilecol={TileCol}&tilematrixset={TileMatrixSet}&format=tiles&tk=' +
				_key;
			if (opts.proxy) //存在代理时
				_url = (0, this.getProxyUrl)({
					url: _url.replace('{s}', '0'),
					proxy: opts.proxy
				}).url;

			layer = new Cesium.WebMapTileServiceImageryProvider({
				url: _url,
				layer: _layer,
				style: 'default',
				format: 'tiles',
				tileMatrixSetID: 'c',
				subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
				tileMatrixLabels: matrixIds,
				tilingScheme: new Cesium
			.GeographicTilingScheme(), //WebMercatorTilingScheme、GeographicTilingScheme
				maximumLevel: maxLevel
			});
		} else {
			//墨卡托  
			var matrixIds = new Array(maxLevel);
			for (var z = 0; z <= maxLevel; z++) {
				matrixIds[z] = z.toString();
			}
			var _url = 'https://t{s}.tianditu.gov.cn/' + _layer +
				'_w/wmts?service=WMTS&version=1.0.0&request=GetTile&tilematrix={TileMatrix}&layer=' + _layer +
				'&style={style}&tilerow={TileRow}&tilecol={TileCol}&tilematrixset={TileMatrixSet}&format=tiles&tk=' +
				_key;

			if (opts.proxy) //存在代理时
				_url = (0, this.getProxyUrl)({
					url: _url.replace('{s}', '0'),
					proxy: opts.proxy
				}).url;
			layer = new Cesium.WebMapTileServiceImageryProvider({
				url: _url,
				layer: _layer,
				style: 'default',
				format: 'tiles',
				tileMatrixSetID: 'w',
				subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
				tileMatrixLabels: matrixIds,
				tilingScheme: new Cesium.WebMercatorTilingScheme(),
				maximumLevel: maxLevel
			});
		}
		return layer;
	}

	/**
	 * @description 高德
	 * @param {Object} opts
	 */
	createAMap(opts) {
		var _url;
		switch (opts.layer) {
			case "vec":
			default:
				//style=7是立体的，style=8是灰色平面的
				_url = 'https://' + (opts.bigfont ? 'wprd' : 'webrd') +
					'0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}';
				break;
			case "img_d":
				_url = 'https://webst0{s}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}';
				break;
			case "img_z":
				_url =
					'https://webst0{s}.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scale=1&style=8';
				break;
			case "time":
				var time = new Date().getTime();
				_url = 'https://tm.amap.com/trafficengine/mapabc/traffictile?v=1.0&;t=1&x={x}&y={y}&z={z}&&t=' +
					time;
				break;
		}
		if (opts.proxy) //存在代理时
			_url = (0, this.getProxyUrl)({
				url: _url.replace('{s}', '1'),
				proxy: opts.proxy
			}).url;
		return new Cesium.UrlTemplateImageryProvider({
			url: _url,
			subdomains: ['1', '2', '3', '4'],
			maximumLevel: 18
		});
	}

	/**
	 * @description 销毁
	 */
	destroy() {
		delete this._scene
		delete this._viewer
		return Cesium.destroyObject(this);
	}
}
export {
	TileLayer
}
